import vue from 'vue';
import VueRouter from 'vue-router';

//使用插件
vue.use(VueRouter);

//引入路由组件
import Home from '@/page/Home/Home.vue';
import Search from '@/page/Search/Search.vue';
import Login from '@/page/Login/Login.vue';
import Goods from '@/page/Goods/Goods.vue';
import SearchDetail from '@/page/SearchDetail/SearchDetail.vue';
import Register from '@/page/Register/Register.vue';


//导入商户个人中心主页
import PersonalCenter from '@/page/PersonalCenter/PersonalCenter.vue';
//导入商户个人中心主页的子级菜单
import myorder from '@/page/PersonalCenter/Myorder.vue';
import grxx from '@/page/PersonalCenter/grxx.vue';
import shrz from '@/page/PersonalCenter/shrz.vue';
import ShoppingTrolley from '@/page/PersonalCenter/ShoppingTrolley.vue';
import PickupAddress from '@/page/PersonalCenter/PickupAddress.vue';
import supplierRecruitment from '@/page/PersonalCenter/SupplierRecruitment.vue';
//结算页面
import Checkout from '@/page/PersonalCenter/Checkout.vue';

//导入商户管理主页
import MerchantHub from '@/page/PersonalCenter2/MerchantHub.vue';

import AllOrder from '@/page/PersonalCenter2/AllOrder.vue';
import FileMaintenance from '@/page/PersonalCenter2/FileMaintenance.vue';
import PendingOrders from '@/page/PersonalCenter2/PendingOrders.vue';
import StayTakeOrders from '@/page/PersonalCenter2/StayTakeOrders.vue';
import AlreadyTakeDelivery from '@/page/PersonalCenter2/AlreadyTakeDelivery.vue';

//导入供应商个人中心主页
import SupplierHomePage from '@/page/PersonalCenter3/SupplierHomePage.vue'
//导入供应商个人中心主页的子级菜单
import SupplierData from '@/page/PersonalCenter3/SupplierData.vue'
import SupplierList from '@/page/PersonalCenter3/SupplierList.vue'
import SupplierMaintain from '@/page/PersonalCenter3/SupplierMaintain.vue'
import SupplierOrderForm from '@/page/PersonalCenter3/SupplierOrderForm.vue'
import SupplierStatistics from '@/page/PersonalCenter3/SupplierStatistics.vue'

//创建m
const router=new VueRouter({
	routes: [
	    //设置重定向
	  {
		path:'/',
		name:'home',
		component:Home
	  },
	  {
	  	path:'/search',
	  	name:'search',
		component:Search
	  },
	  {
	  	path:'/login',
	  	name:'login',
		component:Login
	  },
	  {
	  	path:'/register',
	  	name:'register',
	  	component:Register
	  },
	  {
	  	path:'/goods/:id',
	  	name:'goods',
	  	component:Goods
	  },
	  {
	  	path: '/searchdetail/:keyword',
	  	component: SearchDetail,
	  	/*meta: {showHeaderTop: true, showHeaderSearch: true}*/
	  },
	  {
	  	path: '/checkout',
		name: 'checkout',
		component: Checkout,
		props: true
	  },
	  {
	  	path:'/personalcenter',
	  	name:'personalcenter',
		component:PersonalCenter,
		redirect: '/grxx',
		children: [
			//商户个人中心
			{ path: '/grxx', component: grxx },
			{ path: '/shrz', component: shrz },
			{path: '/myorder',component: myorder},
			{path: '/ShoppingTrolley',component: ShoppingTrolley},
			{path: '/PickupAddress',component: PickupAddress},
			{path: '/supplierRecruitment',component: supplierRecruitment},
		]
	  },
		//商户管理
		{
			path:'/MerchantHub',
			name:'MerchantHub',
			component:MerchantHub,
			children:[
				{ path: '/AllOrder',component:AllOrder},
				{ path: '/FileMaintenance',component:FileMaintenance},
				{ path: '/PendingOrders',component:PendingOrders},
				{ path: '/StayTakeOrders',component:StayTakeOrders},
				{ path: '/AlreadyTakeDelivery',component:AlreadyTakeDelivery},
			]
		},

		//供应商个人中心子级菜单
		{
			path:'/SupplierHomePage',
			name:'SupplierHomePage',
			component:SupplierHomePage,
			children:[
				{ path: '/SupplierList',component:SupplierList},
				{ path: '/SupplierMaintain',component:SupplierMaintain},
				{ path: '/SupplierOrderForm',component:SupplierOrderForm},
				{ path: '/SupplierData',component:SupplierData},
				{ path: '/SupplierStatistics',component:SupplierStatistics},
			]
		},
	  //重定向，在项目跑起来的时候，访问/，立马让他定向到首页
	  {
	    path: '*',
	    redirect: Home,
	  }
	]
})

/* //全局导航守卫
router.beforeEach((to, from, next)=>{
    //如果访问的路由是/login, 不判断直接放行
    if(to.path === '/login')
        return next()
    //从sessionStorage中获取token
    const token = window.sessionStorage.getItem('token')
    if(!token)
        return next('/login')
    next()
})*/

//共享
export default router